package com.antovita.militarymonkey.service;

import java.util.*;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Textures {
	static private Map<String, TextureRegion[]> map = new HashMap<String, TextureRegion[]>();
	static public void clear()
	{
		map.clear();
	}
	static public void loadSprites(String fileName, int sizeX, int sizeY)
	{
		Texture texture; 
		TextureRegion[] regions = new TextureRegion[sizeX * sizeY];
		texture = new Texture(Gdx.files.internal(fileName));
		float deltaX = 1.0f / (float)sizeX;
		float deltaY = 1.0f / (float)sizeY;
		
		int index = 0;
		for (int j = 0; j < sizeY; j++)
		{
			for(int i = 0; i < sizeX; i++)
			{
				regions[index + i] = new TextureRegion(texture, i * deltaX, j * deltaY, 
												deltaX * (i + 1.0f), deltaY * (j + 1.0f));
			}
			index += sizeX;
		}
        map.put(fileName, regions);
	}
	
	static public TextureRegion[] getTextureRegions(String fileName)
	{
		return map.get(fileName);		
	}
}
